

    const encryption = require('../lib/encryption')
    const {user} = require('../model/index')

    module.exports = {

        checkLogin: async (phone, password) => {
            console.log(phone, password)
            try {
                let name = await user.findOne({
                    where: {
                        phone: phone
                    }
                })
                if(name && name.dataValues.password === password) return name.dataValues
                else return null
            } catch(error) {
                console.log("查找用户错误：" + error)
                return false
            }
        },

        register: async (info) => {
            try {
                await user.create({
                    username: info.username,
                    password: await encryption.getMd5Pass(info.password),
                    phone: info.phone,
                    email: info.email,
                    salt: ''
                })
                return true
            } catch(error) {
                console.log("错误信息" + error)
                return false
            }
        }

    }